<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="联系方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="运营商名称" align="center" prop="operatorName" />
      <el-table-column label="联系人名称" align="center" prop="userName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="身份证正面照片" align="center" prop="idCardFront" >
        <template slot-scope="{row}">
          <el-image v-if="row.idCardFront"
            style="width: 100px; height: 100px"
            :src="row.idCardFront"
            :preview-src-list="[row.idCardFront]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="身份证背面照片" align="center" prop="idCardBack" >
        <template slot-scope="{row}">
          <el-image v-if="row.idCardBack"
            style="width: 100px; height: 100px"
            :src="row.idCardBack"
            :preview-src-list="[row.idCardBack]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="applyStatus" >
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.operator_applicat_status" :value="row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(row)"
            v-hasPermi="['trade:operatorApplyRecord:query']"
          >查看详情</el-button>
          <el-button v-if="row.applyStatus === 1"
            size="mini"
            type="text"
            @click="handleAuith(row,2)"
            v-hasPermi="['trade:operatorApplyRecord:edit']"
          >通过审核</el-button>
          <el-button v-if="row.applyStatus === 1"
            size="mini"
            type="text"
            @click="handleAuith(row,3)"
            v-hasPermi="['trade:operatorApplyRecord:edit']"
          >驳回申请</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row class="diy-text-sm diy-leading-10" :gutter="10" v-if="title == '查看详情'">
          <el-col :span="item.span || 12" v-for="(item,index) in formDetail" :key="index">
            <div class="flex_hcneter">
              <svg-icon icon-class="dot" class-name='diy-text-primary diy-mr-1'/>
              <div v-if="item.zidian && item.isCustom" class="flex_hcneter">
                {{item.label}}：<dict-tag :options="dict.type[item.zidian]" :value="form[item.prop]"/>
              </div>
              <div v-else-if="item.prop == 'content' && item.isCustom">
                {{item.label}}：
                <div v-html="form[item.prop]"></div>
              </div>
              <div v-else-if="(item.prop == 'idCardFront' || item.prop == 'idCardBack') && item.isCustom" class="flex_hcneter" style="margin-bottom:10px;">
                {{item.label}}：
                <el-image
                  style="width: 100px; height: 100px;"
                  :src="form[item.prop]"
                  :preview-src-list="[form[item.prop]]">
                </el-image>
              </div>
              <div v-else-if="item.prop == 'picUrlList' && item.isCustom">
                <h2>{{item.label}}</h2>
                <el-row v-for="(item1,index1) in form[item.prop]" :key="index1">
                  <el-col :span="24">
                    <div class="flex_hcneter">
                      <svg-icon  icon-class="dot" class-name='diy-text-primary diy-mr-1'/>
                      文件路径：<el-link type="primary" @click="urlLink(item1)">{{item1}}</el-link>
                    </div>
                  </el-col>
                </el-row>
              </div>
              <div v-else>{{item.label}}：{{ form[item.prop] }}{{ item.danwei || '' }}</div>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOperatorApplyRecord, getOperatorApplyRecord, toPassAudit, toRejectApply, } from "@/api/operator/applicatRecord";
export default {
  name: "ApplicatRecord",
  dicts: ['operator_applicat_status',],
  components: { },
  data() {
    return {
      formDetail:[//表单
        {label:'运营商名称',prop:'operatorName',},{label:'联系人名称',prop:'userName',},{label:'手机号',prop:'phone',},{label:'省',prop:'provinceName',},
        {label:'市',prop:'cityName',},{label:'区',prop:'countyName',},{label:'街道',prop:'townName',},{label:'经度',prop:'longitude',},{label:'纬度',prop:'latitude',},
        {label:'身份证正面照片',prop:'idCardFront',isCustom:true,span:24,},{label:'身份证背面照片',prop:'idCardBack',isCustom:true,span:24,},
        {label:'附件列表',prop:'picUrlList',isCustom:true,span:24,},
        {label:'申请原因',prop:'content',isCustom:true,span:24,},{label:'状态',prop:'applyStatus',zidian:'operator_applicat_status',isCustom:true,},
        {label:'审核时间',prop:'auditTime',},{label:'创建时间',prop:'createTime',},
      ],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    urlLink(row){//链接跳转
      window.open(row)
    },
    /** 查列表 */
    getList() {
      this.loading = true;
      listOperatorApplyRecord(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      const id = row.id
      getOperatorApplyRecord(id).then(response => {
        let data =  response.data || {};
        let picUrl = data.picUrl || ''
        this.form = {
          ...data,
          picUrlList:picUrl ? picUrl.split(',') : []
        }
        this.open = true;
        this.title = "查看详情";
      });
    },
    /** 审核按钮操作 */
    handleAuith(row,status) {
      const id = row.id
      let api = status == 3 ? toRejectApply : toPassAudit
      this.$modal.confirm(`是否确认${status == 3 ? '审核未通过' : '审核通过'}该数据项？`).then(function() {
        return api(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
  }
};
</script>
